//
//  RBGModeleController.m
//  BateauGenerique
//
//  Created by Kevin De Jesus Ferreira on 09/06/2014.
//  Copyright (c) 2014 Kevin De Jesus Ferreira. All rights reserved.
//

#import "RBGModeleController.h"
#import "RBGAppDelegate.h"
#import "UIImageView+WebCache.h"
#import "RBGNavigationBar.h"
#import "Modele.h"

@interface RBGModeleController ()<UITableViewDelegate,UITableViewDataSource>
{
    RBGAppDelegate *appDelegate;
    NSMutableArray * values;
}


@end

@implementation RBGModeleController

- (void)viewDidLoad
{
    [super viewDidLoad];
    appDelegate = (RBGAppDelegate *)[[UIApplication sharedApplication] delegate];
    
    values = [[NSMutableArray alloc]init];
    
    for(Modele * m in self.modeles){
        [values addObject:m.libelle];
    }
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.fond setImageWithURL:[NSURL URLWithString:appDelegate.donnees.parametres.imageFond]];
    self.tableView.backgroundColor = [UIColor clearColor];
    
    [self setTitle:@"Modèles"];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController popViewControllerAnimated:YES];

    
    //[self.delegate receiveValueSelected:index andTypeValeur:self.type];
    
    
    // Peut être pas le bon controller
    Modele * m = [self.modeles objectAtIndex:indexPath.row];
    [self.delegate receiveDonneesRBGModele:m.id andNomModele:m.libelle];


    [self.parentViewController.navigationController popToViewController:self.filtreController animated:NO];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [values count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SimpleCell"];
    
    [cell.textLabel setText:[values objectAtIndex:indexPath.row]];
    
    [cell.textLabel setTextColor:appDelegate.donnees.parametres.fontColorDeux];
    
    [cell.textLabel setFont: [UIFont fontWithName:@"Arial" size:13.0f]];
    
    UIView *selectedView = [[UIView alloc]init];
    selectedView.backgroundColor = appDelegate.donnees.parametres.backgroundColorDeux;
    cell.selectedBackgroundView =  selectedView;
    
    [cell setBackgroundColor:[UIColor clearColor]];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 100 * 2;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * view = [[UIView alloc]init];
    [view setBackgroundColor:[UIColor clearColor]];
    return view;
}


@end
